/*
 * 关键信息说明：localStorage
 * >>登录时，保存用户登录信息 login
 *     account 用户ID
 *     phone   用户账号 手机号
 *     token
 *     tokenExpire
 *     huanId
 * >>选择圈子后，保存导购信息 、圈子名称、群ID quanzilist
 *     guideId,circleName,groupId,circleId
 * >>扫一扫、搜一搜并选择圈子,保存导购信息 quanzilist search
 *     guideId
 * >>圈子购物、店铺商品浏览时，点击商品后保存当前商品信息
 *     goodsId
 * >>在商品详情中，加入购物车时，更新本地购物车信息
 * >>在购物车中编辑时，更新本地购物车信息
 *     buyCar
 * >>购物车结算时，保存临时订单信息;选择一个订单操作时， 保存临时订单信息；操作完成后，删除当时订单信息
 *     order
 * >>进入圈子后，收到其他群消息时，保存到本地
 *     IMmessage
 * >>退出登录时，清除用户登录信息
 * >>本地历史消息
 *   localhistory
 */
//请求地址获取
var signUrl;

function getUrl(urltype) {
	var url;
	//url="http://123.56.69.114:8080";
	//url = "http://123.56.85.113:8080";
	//url = "http://192.168.0.140:8080";
	//url = "http://192.168.0.113:8080";
	//url = "http://192.168.21.17:8080"
	//url = "http://58.gooooo5.com";
	//url = "http://test.gooooo5.com";
	//url = "http://192.168.0.140:8080";
	//url = "http://192.168.0.109:8080";
	url = "http://gooooo5.com";
	switch (urltype) {
		//登录前的请求，无需验证签名
		case "loginPwd":
			//密码登录 1.1.2 login
			url = url + "/yuegou/cApp/account/doPwdLogin";
			break;
		case "checkCode":
			//获取验证码 1.1.1 messageLogin register
			url = url + "/yuegou/v1/cApp/account/sendSMSValdate";
			break;
		case "loginCode":
			//验证码登录 1.1.2 messageLogin
			url = url + "/yuegou/cApp/account/doCodeLogin";
			break;
		case "register":
			//用户注册 1.1.3
			url = url + "/yuegou/cApp/account/doRegister";
			break;
		case "searchPwd":
			//找回密码第一步 6.1.1
			url = url + "/yuegou/cApp/account/doForget";
			break;
		case "findPwd":
			//找回密码第二步 6.1.1
			url = url + "/yuegou/cApp/account/doForget2";
			break;
		case "version":
			//更新版本
			url = url + "/yuegou/cApp/version/findVersion";
			break;
			//登录后的操作，需要验证签名
		case "circleList":
			//圈子列表 4.1.1
			url = url + "/yuegou/v1/cApp/account/circleList";
			signUrl = "account/circleList";
			break;
		case "circleSearch":
			//查找关注 4.1.10
			url = url + "/yuegou/v1/cApp/account/searchByName";
			signUrl = "account/searchByName";
			break;
		case "circleDetail":
			//圈子详情
			url = url + "/yuegou/v2/cApp/account/scannSearch";
			signUrl = "account/scannSearch";
			break;
		case "guanzhu":
			//圈子加关注
			url = url + "/yuegou/cApp/account/attentionCircle";
			signUrl = "account/attentionCircle";
			break;
		case "cancelAttention":
			//取消关注  4.1.9
			url = url + "/yuegou/cApp/account/cancelAttention";
			signUrl = "account/cancelAttention";
			break;
		case "myAttention":
			//我关注的商品
			url = url + "/yuegou/v1/cApp/product/myAttention";
			signUrl = "product/myAttention";
			break;
		case "hotSale":
			//热卖商品
			url = url + "/yuegou/cApp/product/hotSale";
			signUrl = "product/hotSale";
			break;
		case "isNew":
			//新品
			url = url + "/yuegou/cApp/product/isNew";
			signUrl = "product/isNew";
			break;
		case "allAttention":
			//大家关注
			url = url + "/yuegou/v1/cApp/product/allAttention";
			signUrl = "product/allAttention";
			break;
		case "logo":
			//店铺LOGO
			url = url + "/yuegou/cApp/marketShop/getShopLogo";
			signUrl = "marketShop/getShopLogo";
			break;
		case "goodsNum":
			//商品数量（店铺首页）
			url = url + "/yuegou/cApp/marketShop/productCount";
			signUrl = "marketShop/productCount";
			break;
		case "goodsNew":
			//新品上架
			url = url + "/yuegou/v1/cApp/marketShop/getIsNew";
			signUrl = "marketShop/getIsNew";
			break;
		case "18detail":
			//商品详情
			url = url + "/yuegou/v1/cApp/product/productContent";
			signUrl = "product/productContent";
			break;
		case "19spec":
			//商品规格
			url = url + "/yuegou/cApp/product/productSpec";
			signUrl = "product/productSpec";
			break;
		case "20comment":
			//商品评价
			url = url + "/yuegou/cApp/product/productComment";
			signUrl = "product/productComment";
			break;
		case "21buycar":
			//购物车更新
			url = url + "/yuegou/v1/cApp/cart/findProduct";
			signUrl = "cart/findProduct";
			break;
		case "22address":
			//地址列表
			url = url + "/yuegou/cApp/order/selectShipByAccountId";
			signUrl = "order/selectShipByAccountId";
			break;
		case "23invoice":
			//发票列表
			url = url + "/yuegou/cApp/order/invoiceTypeList";
			signUrl = "order/invoiceTypeList";
			break;
		case "24addressAdd":
			//新增地址
			url = url + "/yuegou/cApp/order/addOrderShip";
			signUrl = "order/addOrderShip";
			break;
		case "25orderCreate":
			//创建订单
			url = url + "/yuegou/v2/cApp/order/create";
			signUrl = "order/create";
			break;
		case "26orderStatueSearch":
			//订单查询
			url = url + "/yuegou/v1/cApp/order/selecByOrderStatus";
			signUrl = "order/selecByOrderStatus";
			break;
		case "27invoiceSet":
			//设置发票
			url = url + "/yuegou/cApp/order/invoiceTypeList";
			signUrl = "order/invoiceTypeList";
			break;
		case "28kuaidi":
			//设置快递
			url = url + "/yuegou/cApp/order/expressList";
			signUrl = "order/expressList";
			break;
		case "29receiveCheck":
			//确认收货
			url = url + "/yuegou/cApp/order/confirm";
			signUrl = "order/confirm";
			break;
		case "30orderDelete":
			//订单删除
			url = url + "/yuegou/cApp/order/delete";
			signUrl = "order/delete";
			break;
		case "31orderPj":
			//订单评价
			url = url + "/yuegou/cApp/order/comment";
			signUrl = "order/comment";
			break;
		case "32tuihuoApply":
			//退货申请
			url = url + "/yuegou/cApp/order/applyReturn";
			signUrl = "order/applyReturn";
			break;
		case "33tuohuo":
			//退货发货
			url = url + "/yuegou/cApp/order/applyReturnShipment";
			signUrl = "order/applyReturnShipment";
			break;
		case "34personCenter":
			//个人资料查询
			url = url + "/yuegou/cApp/account/personCenter";
			signUrl = "account/personCenter";
			break;
		case "35uploadFile":
			//上传头像
			url = url + "/yuegou/cApp/account/uploadFile";
			signUrl = "account/uploadFile";
			break;
		case "36findMarket":
			//找商家
			url = url + "/yuegou/cApp/account/findMarket";
			signUrl = "account/findMarket";
			break;
		case "37updataAccount":
			//更新个人资料
			url = url + "/yuegou/cApp/account/updateAccount";
			signUrl = "account/updateAccount";
			break;
		case "38orderDetail":
			//订单详情
			url = url + "/yuegou/v1/cApp/order/selectOrderById";
			signUrl = "order/selectOrderById";
			break;
		case "39addressEdit":
			//地址编辑
			url = url + "/yuegou/cApp/order/editShip";
			signUrl = "order/editShip";
			break;
		case "40addressDel":
			//删除地址
			url = url + "/yuegou/cApp/order/deleteShip";
			signUrl = "order/deleteShip";
			break;
		case "41circleTopic":
			//话题
			url = url + "/yuegou/cApp/topic/getTopicInfo";
			signUrl = "topic/getTopicInfo";
			break;
		case "42zanTopic":
			//话题点赞
			url = url + "/yuegou/cApp/topic/zan";
			signUrl = "topic/zan";
			break;
		case "43replyTopic":
			//话题评论
			url = url + "/yuegou/cApp/topic/review";
			signUrl = "topic/review";
			break;
		case "44allGoods":
			//全部商品
			url = url + "/yuegou/v1/cApp/marketShop/getAllProduct";
			signUrl = "marketShop/getAllProduct";
			break;
		case "45orderCancle":
			//取消订单
			url = url + "/yuegou/cApp/order/cancel";
			signUrl = "order/cancel";
			break;
		case "46tuihuo":
			//退货订单查询
			url = url + "/yuegou/cApp/order/selecRefundOrder";
			signUrl = "order/selecRefundOrder";
			break;
		case "47getAccount":
			//个人资料
			url = url + "/yuegou/cApp/account/getAccountById";
			signUrl = "account/getAccountById";
			break;
		case "48circleMember":
			//获取会员资料
			url = url + "/yuegou/cApp/account/getAccountByUserId";
			signUrl = "account/getAccountByUserId";
			break;
		case "49delTag":
			//管理删除标签
			url = url + "/yuegou/cApp/tag/deleteTag";
			signUrl = "tag/deleteTag";
			break;
		case "50addTag":
			//增加标签
			url = url + "/yuegou/cApp/tag/addTag";
			signUrl = "tag/addTag";
			break;
		case "51getProduct":
			//商品搜索
			url = url + "/yuegou/v1/cApp/marketShop/searchProductByName";
			signUrl = "marketShop/searchProductByName";
			break;
		case "52productGz":
			//商品关注
			url = url + "/yuegou/cApp/account/attentionProduct";
			signUrl = "account/attentionProduct";
			break;
		case "53searchorder":
			//搜素订单
			url = url + "/yuegou/cApp/order/search";
			signUrl = "order/search";
			break;
		case "54uploadFile":
			//上传头像
			url = url + "/yuegou/cApp/account/upload";
			signUrl = "account/upload";
			break;
		case "55advice":
			//意见反馈
			url = url + "/yuegou/cApp/feedback/save";
			signUrl = "feedback/save";
			break;
		case "56wxPay":
			// 微信支付
			url = url + "/yuegou/cApp/order/wxPay";
			signUrl = "order/wxPay";
			break;
		case "57noCircle":
			//推荐的圈子
			url = url + "/yuegou/v1/cApp/account/recommendCircle";
			signUrl = "account/recommendCircle";
			break;
		case "58aliPay":
			//支付宝支付参数
			url = url + "/yuegou/v1/cApp/order/aliPay";
			signUrl = "order/aliPay";
			break;
		case "59token":
			//更新token
			url = url + "/yuegou/cApp/account/token";
			signUrl = "account/token";
			break;
		case "60payList":
			//获取支付方式列表
			url = url + "/yuegou/cApp/order/getPayMethodList";
			signUrl = "order/getPayMethodList";
			break;
		case "61getTag":
			//取得标签
			url = url + "/yuegou/cApp/tag/select";
			signUrl = "tag/select";
			break;
		case "62circleMessage":
			//取得标签
			url = url + "/yuegou/v1/cApp/account/msgList";
			signUrl = "account/msgList";
			break;
		case "63service":
			//取得标签
			url = url + "/yuegou/cApp/serviceOrder/service";
			signUrl = "serviceOrder/service";
			break;
		case "64getlist":
			//取得标签
			url = url + "/yuegou/cApp/serviceOrder/list";
			signUrl = "serviceOrder/list";
			break;
		case "65noTokenaccount":
			//提交个人信息 没有token
			url = url + "/yuegou/cApp/account/updateAccountNoToken";
			signUrl = "account/updateAccountNoToken";
			break;
		case "66selectNoPJ":
			//提交个人信息 没有token
			url = url + "/yuegou/cApp/order/selecByClosedComment";
			signUrl = "order/selecByClosedComment";
			break;
		case "67baokuan":
			//商品爆款
			url = url + "/yuegou/v1/cApp/marketShop/exploProductList";
			signUrl = "marketShop/exploProductList";
			break;
		case "68cuxiao":
			//商品促销
			url = url + "/yuegou/v1/cApp/marketShop/salePromotionList";
			signUrl = "marketShop/salePromotionList";
			break;
		case "69find":
			//发现圈子
			url = url + "/yuegou/cApp/marketShop/marketList";
			signUrl = "marketShop/marketList";
			break;
		case "70marketCircle":
			//推荐的圈子
			url = url + "/yuegou/cApp/account/findCircleByMarketId";
			signUrl = "account/findCircleByMarketId";
			break
		case "71findPayModels":
			//获得支付模式
			url = url + "/yuegou/v1/cApp/order/findPayModels";
			signUrl = "order/findPayModels";
			break;
		case "72selecByOrderStatusNoVerifi":
			//核销
			url = url + "/yuegou/cApp/order/selecByOrderStatusNoVerifi";
			signUrl = "order/selecByOrderStatusNoVerifi";
			break;
		case "73getCatalogs":
			//店铺商品分类
			url = url + "/yuegou/cApp/catalog/getCatalogs";
			signUrl = "catalog/getCatalogs";
			break;
		case "74getCatalogs":
			//门店分类
			url = url + "/yuegou/cApp/systemCatalog/getCatalogs";
			signUrl = "systemCatalog/getCatalogs";
			break;
		case "75getAdvert":
			//广告分类
			url = url + "/yuegou/cApp/advert/getAdvert";
			signUrl = "advert/getAdvert";
			break;
		case "76checkin":
			//广告分类
			url = url + "/yuegou/v1/cApp/accountScore/earnScore";
			signUrl = "accountScore/earnScore";
			break;
		case "77getSignStatus":
			//广告分类
			url = url + "/yuegou/v1/cApp/accountScore/getSignStatus";
			signUrl = "accountScore/getSignStatus";
			break;
		case "78getScore":
			//广告分类
			url = url + "/yuegou/v1/cApp/accountScore/getScore";
			signUrl = "accountScore/getScore";
			break;
		case "79getmessagelist":
			//广告分类
			url = url + "/yuegou/v1/capp/notice/list";
			signUrl = "notice/list";
			break;
		case "80exchageProducts":
			//换购商品
			url = url + "/yuegou/v1/cApp/product/exchageProducts";
			signUrl = "product/exchageProducts";
			break;
		case "81promotionZone":
			//促销专区
			url = url + "/yuegou/v1/cApp/product/promotionZone";
			signUrl = "product/promotionZone";
			break;
		case "82promotionProductList":
			//促销活动
			url = url + "/yuegou/v1/cApp/product/promotionProductList";
			signUrl = "product/promotionProductList";
			break;
		case "83findFlashSaleIdAndTime":
			//限时促销时间段
			url = url + "/yuegou/v1/cApp/product/findFlashSaleIdAndTime";
			signUrl = "product/findFlashSaleIdAndTime";
			break;
		case "84findProductsByUserIdAndActId":
			//限时促销商品
			url = url + "/yuegou/v1/cApp/product/findProductsByUserIdAndActId";
			signUrl = "product/findProductsByUserIdAndActId";
			break;
		case "85nearby":
			url = url + "/yuegou/v2/cApp/marketShop/getNearby";
			signUrl = "marketShop/getNearby";
			break;
		case "86myAttention":
			url = url + "/yuegou/v2/cApp/marketShop/myAttention";
			signUrl = "marketShop/myAttention";
			break;
		case "87shopRecommend":
			url = url + "/yuegou/v2/cApp/marketShop/shopRecommend";
			signUrl = "marketShop/shopRecommend";
			break;
		case "88hots":
			//热卖商品
			url = url + "/yuegou/v2/cApp/product/shopHome/hots";
			signUrl = "shopHome/hots";
			break;
		case "89getMenus":
			url = url + "/yuegou/v2/cApp/marketShop/getMenus";
			signUrl = "marketShop/getMenus";
			break;
		case "90specialProduct":
			url = url + "/yuegou/v2/cApp/marketShop/specialProduct";
			signUrl = "marketShop/specialProduct";
			break;
		case "91shoppeSearch":
			//品牌搜索
			url = url + "/yuegou/v2/cApp/product/shoppeSearch";
			signUrl = "product/shoppeSearch";
			break;
		case "92productSearch":
			//商品搜索
			url = url + "/yuegou/v2/cApp/product/productSearch";
			signUrl = "product/productSearch";
			break;
		case "93recommendCircle":
			url = url + "/yuegou/v2/cApp/marketShop/recommendCircle";
			signUrl = "marketShop/recommendCircle";
			break;
		case "94catalogFind":
			//品牌分类
			url = url + "/yuegou/v2/cApp/marketShop/catalogFind";
			signUrl = "marketShop/catalogFind";
			break;
	}
	return url;
}

//获取验证信息
function getHeader() {
	var userid = readData(localStorage.account);
	var token = readData(localStorage.token);
	var sign = token + userid + signUrl;
	sign = hex_md5(sign);
	var headerJson = {
		'accountId': userid,
		'signature': sign,
		'Content-Type': 'application/x-www-form-urlencoded;charset=utf-8'
	};
	//jsons = eval('(' + headerJson + ')');
	return headerJson;
}

//获取订单状态
function orderStatus(status, isRefund) {
	var orderStatus;
	if (isRefund == "n") {
		switch (status) {
			case 'init':
				orderStatus = "待付款";
				break;
			case 'pass':
				orderStatus = "待发货";
				break;
			case 'send':
				orderStatus = "待收货";
				break;
			case 'sign':
				//orderStatus = "待评价";
				orderStatus = "已签收";
				break;
			case 'cancel':
				orderStatus = "已取消";
				break;
			case 'file':
				orderStatus = "已完成";
				break;
			case 'finish':
				orderStatus = "已关闭";
				break;
				/*case 'noVerifi':
				 orderStatus = "待核销";
				 break;*/
		}
	} else {
		switch (isRefund) {
			case 'WAIT_GUIDE_AGREE':
				orderStatus = "已申请退货";
				break;
			case 'WAIT_EXPRESS_NUM':
				orderStatus = "商品待退回";
				break;
			case 'WAIT_GUIDE_CONFIRM':
				orderStatus = "商品待审核";
				break;
			case 'WAIT_SHOP_CONFIRM':
				orderStatus = "退货审核中";
				break;
			case 'WAIT_MARKET_PAYMENT':
				orderStatus = "等待退款中";
				break;
			case 'REFUND_SUCCESS':
				orderStatus = "退款已完成";
				break;
			case 'CANCEL_REFUND':
				orderStatus = "退货已取消";
				break;
		}

	}
	return orderStatus
}
//刷新购物车
function refershBycar() {
	var detail = plus.webview.getWebviewById("productDetail.html");
	var circleShop = plus.webview.getWebviewById("circleShop.html");
	var buyCar = plus.webview.getWebviewById("buyCar.html");
	if (detail) {
		mui.fire(detail, "refreshBuyCar")
	}
	if (circleShop) {
		mui.fire(circleShop, "refreshBuyCar")
	}
	if (buyCar) {
		mui.fire(buyCar, "refreshBuyCar")
	}

}

//刷新首页
function circleRes() {
	api.execScript({
		name: 'root',
		frameName: 'quanzilist',
		script: 'window.location.reload()'
	});
}

function HomeMessage() {
	api.execScript({
		name: 'root',
		frameName: 'quanzilist',
		script: 'freshenMessage()'
	});
	api.execScript({
		name: 'root',
		frameName: 'quanzilist',
		script: 'shuaxin()'
	});
}

function circlemessage() {
	api.execScript({
		name: 'message',
		script: 'window.location.reload()'
	});
	api.execScript({
		name: 'quanziMessage',
		script: 'window.location.reload()'
	});

	api.execScript({
		name: 'gouwu',
		frameName: 'broadcast-con3',
		script: 'window.location.reload()'
	});
}

//订单管理整页刷新
function orderRes() {
	api.execScript({
		name: 'orderM',
		frameName: 'all',
		script: 'window.location.reload()'
	});
	api.execScript({
		name: 'orderM',
		frameName: 'daifukuan',
		script: 'window.location.reload()'
	});
	api.execScript({
		name: 'orderM',
		frameName: 'daishouhuo',
		script: 'window.location.reload()'
	});
	api.execScript({
		name: 'orderM',
		frameName: 'daipingjia',
		script: 'window.location.reload()'
	});
}

function service() {

	api.execScript({
		name: 'serviceList',
		frameName: 'apply',
		script: 'window.location.reload()'
	});
	api.execScript({
		name: 'serviceList',
		frameName: 'chuli',
		script: 'window.location.reload()'
	});
	api.execScript({
		name: 'serviceList',
		frameName: 'finish',
		script: 'window.location.reload()'
	});
	api.execScript({
		name: 'serviceList',
		frameName: 'cancel',
		script: 'window.location.reload()'
	});

}

if (localStorage.isIos == "true") {
	if (document.getElementById("header")) {
		document.getElementById("header").style.paddingTop = 20 + "px";
	}
	if (document.getElementById("main")) {
		document.getElementById("main").style.marginTop = 68 + "px";
	}
	if (document.getElementById("navBar_fun")) {
		document.getElementById("navBar_fun").style.top = 68 + "px";
	}
	if (document.getElementById("header_meau")) {
		document.getElementById("header_meau").style.top = 68 + "px";
	}
}

if (document.getElementsByTagName("h5")[0]) {
	var h5s = document.getElementsByTagName("h5")[0].textContent;
	if (h5s.length > 15) {
		document.getElementsByTagName("h5")[0].textContent = h5s.substring(0, 14) + "..";
	}
}

function Slide(wrapper, slide, timer) {
	var num = 1,
		swiper_slide, swiper_wrapper, swiper_height;
	this.init = function() {
		swiper_wrapper = document.getElementsByClassName(wrapper)[0];
		swiper_slide = document.getElementsByClassName(slide);
		swiper_height = swiper_slide[0].clientHeight;
		setInterval(this.animates, timer);
	}
	this.animates = function() {
		var space = swiper_height * num;
		swiper_wrapper.style.transitionDuration = "1000ms";
		swiper_wrapper.style.webkitTransitionDuration = "1000ms";
		swiper_wrapper.style.transform = "translate3d(0," + (-space) + "px,0)";
		swiper_wrapper.style.webkitTransform = "translate3d(0," + (-space) + "px,0)";
		num++;
		if (num > swiper_slide.length) {
			swiper_wrapper.style.transitionDuration = "0ms";
			swiper_wrapper.style.webkitTransitionDuration = "0ms";
			num = 0;
			swiper_wrapper.style.transform = "translate3d(0," + (-swiper_height * num) + "px,0)";
			swiper_wrapper.style.webkitTransform = "translate3d(0," + (-swiper_height * num) + "px,0)";
			num = 1;
		}
	}
}